/**
 * 
 */
package org.lex.explorer.directory;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.filechooser.FileView;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.lex.io.filesystem.FileSystem;


public class FileTreeRenderer extends DefaultTreeCellRenderer {
	private FileView fileView = FileSystem.getLocalFileView();

	public FileView getFileView() {
		return fileView;
	}

	public void setFileView(FileView fileView) {
		this.fileView = fileView;
	}

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, false,
		// even "leaf" folders should look like other folders
				row, hasFocus);
		if (value instanceof FileNode) {
			FileNode node = (FileNode) value;
			setText(this.fileView.getName(node.getFile()));
			setIcon(this.fileView.getIcon(node.getFile()));
		}
		return this;
	}
}
